<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <script src="../../layui/layui.js"></script>
</head>
<body>
<style>
    .layui-form {
        margin-top: 30px;
    }

    .demo-login-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>
<form class="layui-form">
    <div class="demo-login-container">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="memberName" value="" lay-verify="required" placeholder="用户名"
                       lay-reqtext="请填写会员名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="idCard" value="" lay-verify="required" placeholder="身份证号"
                       lay-reqtext="请填写身份证号" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="tel" value="" lay-verify="required" placeholder="手机号"
                       lay-reqtext="请填写手机号" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <select name="sex" lay-filter="sex">
                    <option value="">性别</option>
                    <option value="女">女</option>
                    <option value="男">男</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <select name="level" lay-filter="sex">
                    <option value="">会员等级</option>
                    <option value="黄金会员">黄金会员</option>
                    <option value="白金会员">白金会员</option>
                    <option value="钻石会员">钻石会员</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" id="login" >
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="addUser" >添加会员</button>
        </div>
    </div>
</form>

<script>
    layui.use(function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.$;
        // 提交事件
        form.on('submit(addUser)', function (data) {
            let formData = data.field; // 获取表单字段值
            // 此处可执行 Ajax 等操作
            $.ajax({
                url:'/sport/member/add',
                data:formData,
                type:'post',
                dataType:'json',
                success:function (res){
                        if (res.code==0){
                            layer.msg(res.msg,{icon:1},function (){
                                // 关闭弹出层
                                let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                                parent.layer.close(index);
                            })
                        }else {
                            layer.msg(res.msg,{icon:2})
                        }
                }
            })


            // 再执行关闭
            return false; // 阻止默认 form 跳转
        });

    });
</script>
</body>
</html>